//
//  ESCardNewsWordsView.m
//  EasyStyle
//
//  Created by FK on 16/5/9.
//  Copyright © 2016年 FK. All rights reserved.
//

#import "ESCardNewsWordsView.h"

@interface ESCardNewsWordsView ()

@property (nonatomic,assign)NSInteger arrIndex;

@property (nonatomic,strong)NSMutableArray *dividedData;

@end

@implementation ESCardNewsWordsView

- (void)awakeFromNib
{
    self.backgroundColor = [UIColor colorWithHex:@"ebfafa"];
    self.layer.cornerRadius = 3.0;
    
    _arrIndex = 0;
    
    [_changeWords addTarget:self action:@selector(changeNewWords:) forControlEvents:UIControlEventTouchUpInside];
    
    [_leftUpBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    [_leftMiddleBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    [_leftBottomBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    
    [_rightUpBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    [_rightMiddleBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    [_rightBottomBtn addTarget:self action:@selector(getNewsWordDetail:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)loadCardWithData:(NSArray *)resultNewsWords
{
    [self divideSourceData:resultNewsWords];
    
    [self changeNewWords:nil];
}

- (void)divideSourceData:(NSArray *)sourceData
{
    _dividedData = [NSMutableArray arrayWithCapacity:12];
    
    NSInteger index = 0;
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:6];
    
    for (NSString *newsWord in sourceData) {
        if (index == 6) {
            index = 0;
            [_dividedData addObject:arr];
            arr = [NSMutableArray arrayWithCapacity:6];
        }
        [arr addObject:newsWord];
        index++;
    }
}

- (void)changeNewWords:(UIButton *)sender
{
    if (_arrIndex == _dividedData.count) {
        _arrIndex = 0;
    }
    [_leftUpBtn setTitle:_dividedData[_arrIndex][0] forState:UIControlStateNormal];
    [_leftMiddleBtn setTitle:_dividedData[_arrIndex][1] forState:UIControlStateNormal];
    [_leftBottomBtn setTitle:_dividedData[_arrIndex][2] forState:UIControlStateNormal];
    
    [_rightUpBtn setTitle:_dividedData[_arrIndex][3] forState:UIControlStateNormal];
    [_rightMiddleBtn setTitle:_dividedData[_arrIndex][4] forState:UIControlStateNormal];
    [_rightBottomBtn setTitle:_dividedData[_arrIndex][5] forState:UIControlStateNormal];
    
    _arrIndex++;
}

- (void)getNewsWordDetail:(UIButton *)sender
{
    NSString *newsWord = sender.currentTitle;
    if (_newsWordClickBlock) {
        _newsWordClickBlock(newsWord);
    }
    
}

@end
